package com.ysz.component.tableshard.strategy;


import java.util.Date;
import java.time.LocalDate;
import java.time.OffsetDateTime;
import java.time.ZoneId;

/**
 * @ClassName SpecifyDayTableShardStrategy
 * @Description 按指定时间寻找对应的表  需要搭配分表注解中的
 * @Data 14:23
 * @Version 1.0
 * @Author ysz
 */
public class SpecifyDayTableShardStrategy implements TableShardStrategy {

    @Override
    public String tableShard(String originalSql, String tableName, long specifyDay) {
        if (specifyDay != -1) {
            LocalDate from = LocalDate.from(OffsetDateTime.ofInstant(new Date(specifyDay).toInstant(), ZoneId.systemDefault()));
            return originalSql.replace(tableName, tableName + "-" + from);
        }
        return originalSql;
    }
}
